class Solution {
    int findFirstIndex(vector<int>& nums, int target)
    {
        int left = 0, right = nums.size() - 1;
        while (left < right)
        {
            int mid = (right - left) / 2 + left;
            if (nums[mid] >= target)
                right = mid;
            else    
                left = mid + 1;
        }
        if (nums[right] == target)
            return right;
        
        return -1;
    }

    int findLastIndex(vector<int>& nums, int target)
    {
        int left = 0, right = nums.size() - 1;
        while (left < right)
        {
            int mid = (right - left + 1) / 2 + left;
            if (nums[mid] <= target)
                left = mid;
            else
                right = mid - 1;
        }
        if (nums[left] == target)
            return left;
        
        return -1;
    }
public:
    vector<int> searchRange(vector<int>& nums, int target) {
        vector<int> ret(2, -1);
        if (nums.size() == 0)
            return ret;

        ret[0] = findFirstIndex(nums, target);
        ret[1] = findLastIndex(nums, target);

        return ret;
    }
};